
package ree9opdz . mcsn8yds ;

/**
 * The main program that tests the tutorial application.
 **/
public final class EventManager
{
    /**
     * Hides the default no-args constructor.
     **/
    private EventManager ( )
    {
	super ( ) ;
    }

    /**
     * The main program.
     *
     * If the command line argument is "save"
     * then this program creates a new date
     * "My Event" with the current date and saves it.
     *
     * @param args command line arguments.
     **/
    public static void main ( final java . lang . String [ ] args )
    {
        EventManager mgr = new EventManager ( ) ;
        if ( args [ 0 ] . equals ( "store" ) )
	    {
		mgr . createAndStoreEvent
		    ( "My Event" , new java . util . Date ( ) ) ;
	    }
        HibernateUtil . getSessionFactory ( ) . close ( ) ;
    }

    /**
     * Creates an event with the specified title and date and stores it.
     *
     * @param title the specified title
     * @param theDate the specified date
     **/
    private void createAndStoreEvent
	( final java . lang . String title ,
	  final java . util . Date theDate )
    {
        org . hibernate . Session session =
	    HibernateUtil . getSessionFactory ( ) .
	    getCurrentSession ( ) ;
        session.beginTransaction ( ) ;
        Event theEvent = new Event ( ) ;
        theEvent.setTitle ( title ) ;
        theEvent.setDate ( theDate ) ;
        session.save ( theEvent ) ;
        session.getTransaction ( ) . commit (  ) ;
    }
}
